package net.lengwang.iot.middleware.main;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class PacketSender {
    public static void main(String[] args) {
        // 示例数据包
        String string = "BE BE 04 90 01 01 A2 00 00 EB EB";
        String[] packetData = string.split(" ");

        // 将十六进制字符串转换为字节数组
        byte[] packetBytes = new byte[packetData.length];
        for (int i = 0; i < packetData.length; i++) {
            packetBytes[i] = (byte) Integer.parseInt(packetData[i], 16);
        }

        // 模拟推送到127.0.0.1:11030端口
        try (Socket socket = new Socket("127.0.0.1", 11030)) {
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write(packetBytes);
            outputStream.flush();
            System.out.println(">>>test>>>数据包已成功发送到127.0.0.1:11030");
        } catch (IOException e) {
            System.err.println(">>>test>>>发送数据包时发生错误: " + e.getMessage());
        }
    }
}
